package demo05;

/**
 * @author: WangPeng
 * @createTime: 2022/11/01 9:48
 * @description:
 * @version: v1.0
 */
public class TestJoin {
    public static void main(String[] args) {
        JoinDemo joinDemo1 = new JoinDemo("线程A");
        JoinDemo joinDemo2 = new JoinDemo("线程B");
        joinDemo1.start();
        joinDemo2.start();
        try {
            //main允许t1下加入，只有t1线程执行完毕后主线程才会执行。
//            joinDemo1.join();
            joinDemo2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        for (int i = 0; i < 20; i++) {
            System.out.println("main===="+i);
        }
    }
}
class JoinDemo extends Thread{
    public JoinDemo(){

    }

    public JoinDemo(String name){
        super(name);
    }

    @Override
    public void run() {
        for (int i = 0; i < 20; i++) {
            System.out.println(Thread.currentThread().getName()+"执行====="+i);
        }
    }

}
